package com.share.ai.spring.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AiConfig {

    //内存的话就这么点配置
    @Bean
    public ChatMemory chatMemory() {
        InMemoryChatMemory chatMemory = new InMemoryChatMemory();
        return chatMemory;
    }

    //通过参数注入
    @Bean
    public ChatClient chatClient(ChatClient.Builder builder, ChatMemory chatMemory) {
        ChatClient chatClient = builder.defaultSystem("我是ai医生,有啥可以帮到你的") //预设角色
                .defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build()) //内存记忆
                .build();

        return chatClient;
    }
}
